package controller

import (
	"github.com/gin-gonic/gin"
	"main/service"
	"main/tool"
)

type FoodCategoryController struct {
	
}

func (fcc *FoodCategoryController) Router(engine *gin.Engine) {
	engine.GET("/api/food_category", fcc.FootCategory)
}


func (fcc *FoodCategoryController) FootCategory(ctx *gin.Context) {
	// service
	fcs := &service.FoodCategoryService{}

	categories, err := fcs.Categories()
	if err != nil {
		tool.Failed(ctx, "get categories:" + err.Error())
		return
	}

	// 转换格式
	for _, category := range categories {
		if category.ImageUrl != "" {
			category.ImageUrl = tool.FileServerAddr() + "/" + category.ImageUrl
		}
	}
	tool.Success(ctx, categories)
}
